﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfQQMusic
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        //MenuWindow menuWindow = new MenuWindow();

        bool isPressed = false;
        public MainWindow()
        {
            InitializeComponent();
          
            this.MouseMove += (render, e) =>
            {
                if (e.LeftButton == MouseButtonState.Pressed)
                {
                    this.DragMove();
                }
            };

            List<Menu> onlineMusicMenu = new List<Menu>();
            onlineMusicMenu.Add(new Menu { Icon = "\xe7b8", MenuName = "音乐馆" });
            onlineMusicMenu.Add(new Menu { Icon = "\xe604", MenuName = "视频" });
            onlineMusicMenu.Add(new Menu { Icon = "\xe6ca", MenuName = "电台" });

            List<Menu> myMusicMenu = new List<Menu>();
            myMusicMenu.Add(new Menu { Icon = "\xe63b", MenuName = "我喜欢" });
            myMusicMenu.Add(new Menu { Icon = "\xe641", MenuName = "本地和下载" });
            myMusicMenu.Add(new Menu { Icon = "\xe622", MenuName = "播放历史" });
            myMusicMenu.Add(new Menu { Icon = "\xe639", MenuName = "试听列表" });
            myMusicMenu.Add(new Menu { Icon = "\xe6a3", MenuName = "已购音乐" });


            List<SongList> songList = new List<SongList>();
            songList.Add(new SongList { Icon1 = "\xe66e", Icon2 = "\xe62d", SongListName = "创建的歌单" });
            songList.Add(new SongList { Icon1 = "    ", Icon2 = "\xe62d", SongListName = "收藏的歌单" });


            List<TIcon> nextControlList = new List<TIcon>();
            nextControlList.Add(new TIcon { Icon = "\xe50b" });
            nextControlList.Add(new TIcon { Icon = "\xe62a" });

            List<Filter> filterControlList = new List<Filter>();
            filterControlList.Add(new Filter { FilterName="精选" });
            filterControlList.Add(new Filter { FilterName = "排行" });
            filterControlList.Add(new Filter { FilterName = "歌手" });
            filterControlList.Add(new Filter { FilterName = "分类歌单" });
            filterControlList.Add(new Filter { FilterName = "数字专辑" });
            filterControlList.Add(new Filter { FilterName = "有声节目" });


            this.onlineMusicListBox.ItemsSource = onlineMusicMenu;
            this.myMusicListBox.ItemsSource = myMusicMenu;
            this.myControl.ItemsSource = songList;
            this.nextControl.ItemsSource = nextControlList;
            this.filterControl.ItemsSource = filterControlList;
        }

        public class Menu
        {
            public string Icon { get; set; } 
            public string MenuName { get; set; }
        }

        public class SongList
        {
            public string Icon1 { get; set; }
            public string Icon2 { get; set; }
            public string SongListName { get; set; } 
        }

        public class TIcon
        {
            public string Icon { get; set; }
        }

        public class Filter
        {
            public string FilterName { get; set; }
        }

        //去除搜索框的焦点
        private void LostFocused(object sender, MouseButtonEventArgs e)
        {
            this.searchMusicBox.MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
            //this.MenuGrid.Visibility = Visibility.Hidden;
            if (isPressed != true)
            {
                this.MenuGrid.Visibility = Visibility.Hidden;
              
            }
            isPressed = false;
        }

        private void Close(object sender, MouseButtonEventArgs e)
        {
            Application.Current.Shutdown();
        }

        private void Min(object sender, MouseButtonEventArgs e)
        {

            if (WindowState != WindowState.Minimized)
            {
                WindowState = WindowState.Minimized;
            }

        }

        private void PopWindow(object sender, MouseButtonEventArgs e)
        {
            this.MenuGrid.Visibility = Visibility.Visible;
            isPressed = true;
        }

        private void ShowPanel(object sender, MouseButtonEventArgs e)
        {
            Storyboard sb = new Storyboard();
            //Margin="0,0,-300,0"
            ThicknessAnimation ta = new ThicknessAnimation();
            ta.From = new Thickness() { Left = 0, Top = 0, Right = -260, Bottom = 0 };
            ta.To = new Thickness() { Left = 0, Top = 0, Right = 0, Bottom = 0 };
            ta.Duration = TimeSpan.FromSeconds(0.25);
            Storyboard.SetTarget(ta, RightPanel);
            Storyboard.SetTargetProperty(ta, new PropertyPath("Margin"));
            sb.Children.Add(ta);
            sb.Begin();
        }

        private void HidePanel(object sender, MouseButtonEventArgs e) 
        {
            Storyboard sb = new Storyboard();
            //Margin="0,0,-300,0"
            ThicknessAnimation ta = new ThicknessAnimation();
            ta.From = new Thickness() { Left = 0, Top = 0, Right = 0, Bottom = 0 };
            ta.To = new Thickness() { Left = 0, Top = 0, Right = -260, Bottom = 0 };
            ta.Duration = TimeSpan.FromSeconds(0.25);
            Storyboard.SetTarget(ta, RightPanel);
            Storyboard.SetTargetProperty(ta, new PropertyPath("Margin"));
            sb.Children.Add(ta);
            sb.Begin();  
        } 
    }  
}
